package com.itfreer.data.report.service;

import java.util.HashMap;
import java.util.List;

import com.itfreer.data.report.dao.BaseReportDao;
import com.itfreer.data.report.service.BaseReportService;


/**
 * 定义表单下标准Service实现基类
 * @param <T>
 */
public abstract class BaseReportServiceImp<T> implements BaseReportService<T> {

	protected abstract BaseReportDao getDao();
	
	/*@SuppressWarnings({ "rawtypes" })
	private Class getTClass() {
		Class entityClass = (Class) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0];
		return entityClass;
	}
	
	@SuppressWarnings("unchecked")
	private T getNewT() {
		T entity = null;
		try {
			entity = (T) getTClass().newInstance();
		} catch (InstantiationException | IllegalAccessException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
		return entity;
	}*/
	
	@Override
	public String getSqlWhere(T entity,HashMap<String, Object> where) {
		
		// TODO Auto-generated method stub 
		String sqlWhere = ReportUtil.getWhere(entity, where);
		return sqlWhere;
	}
	
	@Override
	public List getReports(T entity,HashMap<String, Object> where,String sql,String ortherWhere) {
		
		String sqlWhere= this.getSqlWhere(entity, where);
		
		if("" != sqlWhere && null != sqlWhere) {
			sql += " and "+sqlWhere;	
		}
		
		if("" != ortherWhere && null != ortherWhere) {
			sql += " "+ortherWhere;	
		}
		List list = getDao().getReportData(sql);
		return list;
	}
	
}